Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

WP-r55671: Taxonomy: Always lazily load term meta. #276

Merged
merged 13 commits into from
Nov 12, 2023
Merged

Conversation

mattyrob
Copy link
Collaborator

@mattyrob mattyrob commented Nov 1, 2023

Description

Taxonomy: Always lazily load term meta.

In [34529] introduced lazy loading of term meta. However, this was only in the context of WP_Query. Other parts of the codebase, like WP_Term_Query did not lazily load term meta. In this change, calls to update_termmeta_cache are now replaced with wp_lazyload_term_meta, that instead of priming term meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.

Props spacedmonkey, mukesh27, peterwilsoncc.
https://core.trac.wordpress.org/changeset/55671

Motivation and context

Backport of upstream efficiency enhancements
55671 required previous changeset 55608 to be backported. Further changes in changesets 55747 and 55826 are also included and these required 55745 and 55818 respectively.

https://core.trac.wordpress.org/changeset/55608
https://core.trac.wordpress.org/changeset/55671
https://core.trac.wordpress.org/changeset/55745
https://core.trac.wordpress.org/changeset/55747
https://core.trac.wordpress.org/changeset/55749
https://core.trac.wordpress.org/changeset/55818
https://core.trac.wordpress.org/changeset/55826
https://core.trac.wordpress.org/changeset/55855
https://core.trac.wordpress.org/changeset/55856

How has this been tested?

This is a grouped backport, local tests have been passing at each stage.

Screenshots

N/A

Types of changes

  • Code efficiency enhancement

spacedmonkey and others added 8 commits November 1, 2023 08:29
…nclude current object id.

The existing lazy loading meta api, creates a queue of ids, to be primed, if the `get_comment_meta` or `get_term_meta` functions are called. However, it did not check to see if the requested id was in the queue, before prime all the ids in the queue. Now, it adds the id to the queue, is not already in the queue, saving a cache lookup / database query.

WP:Props spacedmonkey, peterwilsoncc, mukesh27, flixos90.
Fixes https://core.trac.wordpress.org/ticket/57901.

---

Merges https://core.trac.wordpress.org/changeset/55608 / WordPress/wordpress-develop@7130af403f to ClassicPress.
In https://core.trac.wordpress.org/changeset/34529 introduced lazy loading of term meta. However, this was only in the context of `WP_Query`. Other parts of the codebase, like `WP_Term_Query` did not lazily load term meta. In this change, calls to `update_termmeta_cache` are now replaced with `wp_lazyload_term_meta`, that instead of priming term meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.

WP:Props spacedmonkey, mukesh27, peterwilsoncc.
Fixes https://core.trac.wordpress.org/ticket/57645.

---

Merges https://core.trac.wordpress.org/changeset/55671 / WordPress/wordpress-develop@2c6bf77a9e to ClassicPress.
…sts.

 Tests: Use the function get_num_queries across all unit tests.

Replace use of $wpdb->num_queries with a function call to get_num_queries. This improves readability and consistency between tests.

Props SergeyBiryukov, peterwilsoncc, spacedmonkey.
In https://core.trac.wordpress.org/changeset/36566 a framework to lazily load metadata was introduced. This supported term and comment meta by default. In this commit, extends support for site ( blog ) meta. Site meta is not heavily used by core and is used by developers to extend multisite. In this change, `_prime_site_caches` and `WP_Site_Query` now call the new function `wp_lazyload_site_meta`. The function `wp_lazyload_site_meta` accepts an array of ids and adds them to the queue of metadata to be lazily loaded. The function `get_blogs_of_user` was updated to now lazily load site meta.

Follow on from https://core.trac.wordpress.org/changeset/55671.

WP:Props spacedmonkey, johnjamesjacoby, peterwilsoncc, mukesh27.
Fixes https://core.trac.wordpress.org/ticket/58185.

---

Merges https://core.trac.wordpress.org/changeset/55747 / WordPress/wordpress-develop@1a5b52a17e to ClassicPress.
…le if class does not exist.

Follow on from https://core.trac.wordpress.org/changeset/55747.

As `get_sites` can be called very early in the bootstrap process, like in the sunrise.php file, it means that the `WP_Metadata_Lazyloader` may not have been loaded yet in the wp-settings.php file. Add a simple check to see if the class exists and if it does not exist then load the class file in.

WP:Props spacedmonkey, peterwilsoncc, dd32.
See https://core.trac.wordpress.org/ticket/58185.

---

Merges https://core.trac.wordpress.org/changeset/55818 / WordPress/wordpress-develop@ac87b8701f to ClassicPress.
…le if class in meta.php.

In https://core.trac.wordpress.org/changeset/55818 did a check to see if `WP_Metadata_Lazyloader` class existed and the loaded in the class file if it did not. However, require in wp-settings.php was not removed and resulted in the class being loaded twice. To be safe, only include the class file in meta.php and remove from wp-settings.php file.

WP:Props spacedmonkey, ryelle.
See https://core.trac.wordpress.org/ticket/58185.

---

Merges https://core.trac.wordpress.org/changeset/55826 / WordPress/wordpress-develop@7d96c1d5f0 to ClassicPress.
Copy link
Member

@xxsimoxx xxsimoxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

spacedmonkey and others added 5 commits November 3, 2023 20:17
In https://core.trac.wordpress.org/changeset/34270 introduced lazy loading of comment meta. However, this was only in the context of `WP_Query`. Other parts of the codebase, like `WP_Comment_Query` did not lazily load comment meta. In this change, calls to `update_meta_cache` are now replaced with `wp_lazyload_comment_meta`, that instead of priming comment meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where comment meta is being primed unnecessarily and never used. Adding everything to the comment meta queue, also means that if comment meta is used, that is all loaded in a single database / cache call.

Follow on from https://core.trac.wordpress.org/changeset/55671, https://core.trac.wordpress.org/changeset/55747.

WP:Props spacedmonkey, peterwilsoncc, flixos90, mukesh27.
Fixes https://core.trac.wordpress.org/ticket/57801.

---

Merges https://core.trac.wordpress.org/changeset/55749 / WordPress/wordpress-develop@3114eda235 to ClassicPress.
…yload function.

As of https://core.trac.wordpress.org/changeset/55749 wp_queue_comments_for_comment_meta_lazyload is no longer used in core. This commit, deprecates this function. Update docs and tests accordingly.

WP:Props sh4lin, spacedmonkey, costdev, peterwilsoncc.
Fixes https://core.trac.wordpress.org/ticket/58301.

---

Merges https://core.trac.wordpress.org/changeset/55855 / WordPress/wordpress-develop@48683a21fe to ClassicPress.
… function to the correct file.

As of https://core.trac.wordpress.org/changeset/55855 wp_queue_comments_for_comment_meta_lazyload was deprecated. But deprecate to wp-admin/deprecated.php and not wp-includes/deprecated.php.This is incorrect, as this is a public function and not an admin function.

WP:Props SergeyBiryukov, spacedmonkey.
See https://core.trac.wordpress.org/ticket/58301.

Conflicts:
- src/wp-includes/deprecated.php

---

Merges https://core.trac.wordpress.org/changeset/55856 / WordPress/wordpress-develop@69718b2612 to ClassicPress.
@viktorix
Copy link
Member

Looks good.

@mattyrob
Copy link
Collaborator Author

Has two approvals, merging in preparation for v2 repository migration.

@mattyrob mattyrob merged commit 360e539 into develop Nov 12, 2023
9 checks passed
@mattyrob mattyrob deleted the merge/wp-r55671 branch November 12, 2023 11:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants